package xiaoqianlang.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import xiaoqianlang.pojo.User;

/**
 * @Author：xiaoqianlang
 * @Package：xiaoqianlang.mapper
 * @Project：PasswordManage
 * @name：UserMapper
 * @Date：2025/4/3/周四 14:22
 * @Filename：UserMapper
 */


@Mapper
public interface UserMapper {

    @Insert("INSERT INTO user(username,email,password_hash,salt) VALUES (#{username},#{email},#{password_hash},#{salt})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insertUser(User user);

    @Select("SELECT * FROM user WHERE username=#{username}")
    User findByUsername(String username);

    @Select("SELECT * FROM user WHERE email = #{email}")
    User findByEmail(String email);
    //用户信息查询{id username email)
    @Select("SELECT id,username,email,created_at AS createdAt FROM user WHERE id = #{id}")
    User findById(Long userid);

}
